home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
demos
/
GL
/
atlantis
/
swim.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
103 lines
/*
* Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
#include "gl.h"
#include "device.h"
#include "math.h"
#include "atlantis.h"
#include "fish.h"
int sign = 1;
whalopilot(struct fish *pfish)
{
pfish->phi = -20.0;
pfish->theta = 0.0;
pfish->psi -= 0.5;
pfish->x += WHALESPEED * pfish->v * cos(pfish->psi / RAD)
* cos(pfish->theta / RAD);
pfish->y += WHALESPEED * pfish->v * sin(pfish->psi / RAD)
* cos(pfish->theta / RAD);
pfish->z += WHALESPEED * pfish->v * sin(pfish->theta / RAD);
}
sharkopilot(struct fish *pfish)
{
float X,Y,Z,tpsi,ttheta,thetal;
pfish->xt = 60000.0;
pfish->yt = 0.0;
pfish->zt = 0.0;
X = pfish->xt - pfish->x;
Y = pfish->yt - pfish->y;
Z = pfish->zt - pfish->z;
thetal = pfish->theta;
ttheta = RAD * fatan( Z / (sqrt(X * X + Y * Y)));
if(ttheta > pfish->theta + 0.25)
pfish->theta += 0.5;
else if(ttheta < pfish->theta - 0.25)
pfish->theta -= 0.5;
if(pfish->theta > 90.0) pfish->theta = 90.0;
if(pfish->theta < -90.0) pfish->theta = -90.0;
pfish->dtheta = pfish->theta - thetal;
tpsi = RAD * fatan2(Y,X);
pfish->attack = 0;
if(fabs(tpsi - pfish->psi) < 10.0) {
pfish->attack = 1;
} else if(fabs(tpsi - pfish->psi) < 45.0) {
if(pfish->psi > tpsi) {
pfish->psi -= 0.5;
if(pfish->psi < -180.) pfish->psi += 360.;
} else if(pfish->psi < tpsi) {
pfish->psi += 0.5;
if(pfish->psi > 180.) pfish->psi -= 360.;
}
} else {
if (rand()%100 > 98) sign = 1 - sign;
pfish->psi += sign;
if(pfish->psi > 180.) pfish->psi -= 360.;
if(pfish->psi < -180.) pfish->psi += 360.;
}
if(pfish->attack) {
if(pfish->v < 1.1) pfish->spurt = 1;
if(pfish->spurt) pfish->v += 0.2;
if(pfish->v > 5.0) pfish->spurt = 0;
if((pfish->v > 1.0) && (!pfish->spurt)) pfish->v -= 0.2;
} else {
if(!(rand() % 400) && (!pfish->spurt)) pfish->spurt = 1;
if(pfish->spurt) pfish->v += 0.05;
if(pfish->v > 3.0) pfish->spurt = 0;
if((pfish->v > 1.0) && (!pfish->spurt)) pfish->v -= 0.05;
}
pfish->x += SHARKSPEED * pfish->v * cos(pfish->psi / RAD)
* cos(pfish->theta / RAD);
pfish->y += SHARKSPEED * pfish->v * sin(pfish->psi / RAD)
* cos(pfish->theta / RAD);
pfish->z += SHARKSPEED * pfish->v * sin(pfish->theta / RAD);
}